<template>
  <base-layout>
    <template #searchPanel>
      <el-row :gutter="20">
        <search-panel
          v-slot="{ form }"
          @search="search"
          :showAddButton="true"
          @insert="addService"
          :addPer="'yk:save'"
          :selectPer="'yk:page'"
          addTitle="新增"
        >
          <el-select
            clearable
            style="width: 150px"
            v-model="form.typeDictId"
            placeholder="移库类型:"
          >
            <!-- <el-option label="全部" value=""></el-option> -->
            <el-option
              v-for="item in getDict['进口来源']"
              :key="item.index"
              :value="item.index"
              :label="item.text"
            />
          </el-select>
          <el-select
            clearable
            style="width: 150px"
            v-model="form.storeId"
            placeholder="门店:"
          >
            <el-option
              v-for="item in stores"
              :key="item.id"
              :value="item.id"
              :label="item.storeName"
            />
          </el-select>
          <el-date-picker
            v-model="form.time"
            type="daterange"
            range-separator="-"
            start-placeholder="申请开始日期"
            end-placeholder="申请结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </search-panel>
      </el-row>
    </template>

    <template #contentPanel>
      <data-table
        :value="tableData"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        :width="160"
      >
        <template #action="{ row }">
            <i
            class="el-icon-s-claim"
            title="审核"
            v-if="row.reviewStatus==='待审批'||row.reviewStatus===null"
            style="margin-left: 15px; cursor: pointer"
            @click="applyTransfer(row, 0)"
          ></i>
          <i
            v-if="row.reviewStatus==='待审批'|| row.reviewStatus===	'审批未通过'"
            class="el-icon-edit"
            title="修改"
            style="margin-left: 15px; cursor: pointer"
            @click="interestsInfo(row, 0)"
          ></i>
          <i
            class="el-icon-delete"
            title="删除"

            style="color: red; margin-left: 15px; cursor: pointer"
            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>

        <ApplyDialog @apply-dialog="apply" :is-radio="true"/>
    </template>
  </base-layout>
</template>

<script>
import { getDict } from '@/utils/index'
import baseMixin from '@/mixins/base'
import ApplyDialog from '@/components/ApplyDialog'

import {
  dataList,
  deleteData,
  auditIsOk
} from '@/api/pre-sale/newCarStock/moveStorageApply'
import { mapGetters } from 'vuex'

export default {
  components: { ApplyDialog },
  mixins: [
    baseMixin({
      idName: 'id',
      dataName: ['content', 'totalRecords'],
      findData: dataList,
      deleteData
      // format(res) {
      //   return res.map((data) => {
      //     data.statusName = data.status === true ? '启用' : '禁用'
      //     return data
      //   })
      // }
    })
  ],
  computed: {
    ...mapGetters(['stores'])
  },
  data() {
    return {
      getDict: getDict(['进口来源']),
      tableColumnAttributes: [
        { name: '移库单号', value: 'code', type: 'text' },
        { name: '申请门店', value: 'storeName', type: 'text' },
        { name: '移库类型', value: 'typeDictValue', type: 'text' },
        { name: '目标库/仓位', value: 'storage', type: 'text', width: '200px' },
        { name: '车辆数', value: 'carNum', type: 'text' },
        { name: '状态', value: 'reviewStatus', type: 'text' },
        { name: '创建人', value: 'createUserName', type: 'text' },
        { name: '申请时间', value: 'createTime', type: 'text', width: '200px' },
        { name: '备注', value: 'remark', type: 'text' },
        { name: '审核不通过原因', value: 'noSuccessDesc', type: 'text' }
      ]
    }
  },
  async created() {},
  methods: {
    // 审核
    async apply(params) {
      console.log(params)
      const { success } = await auditIsOk({ ...params, sourceCode: this.currentRow.code })
      if (success) {
        this.currentRow = {}
        this.setTableData()
        this.$store.dispatch('others/setDialog', {
          visible: false,
          title: '移库审核'
        })
      }
    },
    interestsInfo({ id }) {
      this.$router.push({ name: 'editMoveStorageApply', params: { id }})
    },
    search(form) {
      form.startTime = form.time[0]
      form.endTime = form.time[1]
      delete form['time']
      this.searchOptions = form
      this.currentPage = 1
      this.setTableData()
    },
    addService() {
      this.$router.push({ name: 'addMoveStorageApply' })
    },
    applyTransfer(row) {
      this.$store.dispatch('others/setDialog', {
        visible: true,
        title: '移车审核'
      })
      this.currentRow = row
      this.dialogVisibleForm = true
    }
  }
}
</script>

<style lang="scss" scoped>
.vLine {
  border-left: solid 3px black;
  height: 16px;
  vertical-align: bottom;
  display: inline-block;
}
</style>
